package com.kj.xuyuan.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.kj.xuyuan.R;
import com.kj.xuyuan.widget.LoadingDialog;

import androidx.fragment.app.Fragment;
import butterknife.ButterKnife;

public abstract class BaseFragment extends Fragment {
    private View mContentView = null;
    public String TAG = getClass().getSimpleName();
    private LoadingDialog dialog;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (mContentView == null) {
            mContentView = inflater.inflate(setLayoutResourceID(), null);
            ButterKnife.bind(this, mContentView);
        }
        dialog = new LoadingDialog(getActivity(),getString(R.string.loading));
        initView();
        initData();
        return mContentView;
    }

    /**
     * 此方法用于返回Fragment设置ContentView的布局文件资源ID * * @return 布局文件资源ID
     */
    protected abstract int setLayoutResourceID();

    /**
     * 一些View的相关操作
     */
    protected abstract void initView();

    /**
     * 一些Data的相关操作
     */
    protected abstract void initData();

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    public void showDialog(){
        if(dialog != null){
            dialog.show();
        }
    }

    public void dismissDialog(){
        if(dialog != null){
            dialog.dismiss();
        }
    }
}
